<html>
<head>
<title>
Test for contextmenu event target
</title>
</head>
<body onload="test()">
<p>This test checks if contextmenu event target is correct when triggered from menu key.</p>
<a href="" id="anchor" oncontextmenu="handleContextMenu(event);">Test</a>
<div id="result">FAIL</div>
<script>
var count = 0;
function handleContextMenu(e) {
    count++;
    if(count === 2)
        document.getElementById("result").innerHTML =  "PASS";
    return false;
}

function test() {
    if (window.testRunner)
        testRunner.dumpAsText();
    
    if (!window.eventSender)
        return;
    
    var anchor = document.getElementById("anchor");
    
    var r = anchor.getBoundingClientRect();
    var x = (r.left + r.right) / 2
    var y = (r.top + r.bottom) / 2;
    eventSender.mouseMoveTo(x, y);
    eventSender.contextClick();
    // Esc key to hide context menu
    eventSender.keyDown("Escape");
    anchor.focus();
    eventSender.keyDown("ContextMenu");

}
</script>
</body>
</html>
